package com.vm.widget;

import com.vm.activity.GoodsDetailsActivity;
import com.vm.adapter.ImageAdapter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.Gallery;

@SuppressWarnings("deprecation")
public class GuideGallery extends Gallery {
	private int verticalMinDistance = 10;

	private int minVelocity = 0;
	private GoodsDetailsActivity m_iact;

	public GuideGallery(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	public GuideGallery(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public GuideGallery(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public void setImageActivity(GoodsDetailsActivity iact) {
		this.m_iact = iact;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		if (e1.getX() - e2.getX() > verticalMinDistance
				&& Math.abs(velocityX) > minVelocity) { // Check if scrolling
														// left
			System.out.println("AAAA" + this.getSelectedItemPosition());
		} else if (e2.getX() - e1.getX() > verticalMinDistance
				&& Math.abs(velocityX) > minVelocity) { // Otherwise scrolling
														// right
			System.out.println("BBB" + this.getSelectedItemPosition());
		}
		if (this.getSelectedItemPosition() == 0)
			this.setSelection(ImageAdapter.imageUrl.length);
		System.out.println("DDD" + this.getSelectedItemPosition());
		((GoodsDetailsActivity) m_iact).changePointView(this
				.getSelectedItemPosition() % ImageAdapter.imageUrl.length);
		// new java.util.Timer().schedule(new TimerTask(){
		// public void run() {
		// m_iact.timeFlag = false;
		// this.cancel();
		// }}, 3000);
		return true;

	}

	@SuppressWarnings("unused")
	private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
		System.out.println(this.getSelectedItemPosition());
		return e2.getX() > e1.getX();

	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		// TODO Auto-generated method stub
		// m_iact.timeTaks.timeCondition = false;
		return super.onScroll(e1, e2, distanceX, distanceY);
	}

}
